<style>
    .import {
        opacity: 0;
        position: absolute;
        width: 69px;
        height: 38px;
        margin-left: -10px;
    }
</style>

<!-- 正文开始 -->
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-card-body">
            <div id="searchDIV">
                <!--                搜索框-->
            </div>
            <!-- 表格 -->
            <!--            <table class="layui-table" id="customerTable" lay-filter="customerTable"></table>-->
            <table class="layui-table" id="customerProductCatalogTable"
                   lay-filter="customerProductCatalogTable"></table>
        </div>
    </div>
</div>
<!--搜索组件-->
<script type="text/html" id="searchContent">
    <div class="layui-form lay-header">
        <div class="toolbar">
            <div class="layui-form-item lay-query-content">
                <div class="lay-query-box">
                    <div class="query-lt">
                        <div class="layui-inline">
                            <label class="layui-form-label w-auto">物料名称：</label>
                            <div class="layui-input-inline">
                                <input name="cusProductName" class="layui-input" type="text"
                                       placeholder="请输入物料名称"/>
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button class="layui-btn icon-btn color-green" lay-filter="formSubSearchLog"
                                    layui-form-keyDownSearch="true" lay-submit>查询
                            </button>
                            <button class="layui-btn icon-btn color-white" lay-filter="resets" lay-submit>重置</button>
                        </div>
                    </div>
                    <div class="query-rt"></div>
                </div>
            </div>
        </div>
        <div class="lay-btn-rows">
            <div class="lay-btn-box">
                <div class="lay-btn-lt">
                    <button id="addSelfCollectedGoodsBtn" class="layui-btn icon-btn color-green"
                            lay-filter="addSelfCollectedGoodsBtn">添加
                    </button>
                    <button class="layui-btn icon-btn color-reseda"><input
                            id="uploaderInput" type="file" name="file" class="import" accept=".xls,.xlsx"/>导入
                    </button>
                </div>
                <div class="lay-btn-rt">
                    <button id="gigili" class="layui-btn icon-btn color-green" lay-filter="gigili">下载模版</button>
                </div>
            </div>
        </div>
    </div>
</script>

<!-- 表格操作列 -->
<script type="text/html" id="customerProductCatalogTableBar">
    <!--<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="edit">修改</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>-->
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">详情</a>
    <a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">修改</a>
    <!--<a class="layui-btn  layui-btn-xs" lay-event="">成本核算</a>-->
</script>

<!-- 表单弹窗 -->
<script type="text/html" id="customerProductCatalogForm">
    <form lay-filter="customerProductCatalogForm" class="layui-form model-form">
        <input name="id" type="hidden"/>
        <div class="layui-form-item">
            <label class="layui-form-label width105">客户</label>
            <div class="layui-input-inline">
                <select name="customerId" id="customerId" class="selectDisabled" lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">品牌</label>
            <div class="layui-input-inline">
                <select name="productBrand" id="productBrand" class="selectDisabled" lay-search></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料类型</label>
            <div class="layui-input-inline">
                <select lay-filter="productType" name="productType" id="productType" class="selectDisabled"></select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">规格参数1</label>
            <div class="layui-input-inline">
                <input name="specificationsOne" placeholder="请输入规格参数1" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">规格参数2</label>
            <div class="layui-input-inline">
                <input name="specificationsTwo" placeholder="请输入规格参数2" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">规格码</label>
            <div class="layui-input-inline">
                <input name="specificationCode" placeholder="请输入规格码" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料名称</label>
            <div class="layui-input-inline">
                <input name="productName" placeholder="请输入物料名称" type="text" class="layui-input"
                       lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">物料料号</label>
            <div class="layui-input-inline">
                <input name="productNumber" placeholder="请输入物料料号" type="text" class="layui-input"
                       lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否需要包装</label>
            <div class="layui-input-inline">
                <select name="packing">
                    <option value="">请选择</option>
                    <option value="ypackage">需要包装</option>
                    <option value="npackage">不需要包装</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">包装要求说明</label>
            <div class="layui-input-inline">
                <input name="packingRequire" placeholder="请输入包装要求说明" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">是否表面处理</label>
            <div class="layui-input-inline">
                <select name="surfaceTreatment">
                    <option value="">请选择</option>
                    <option value="yhandle">需要</option>
                    <option value="nhandel">不需要</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">图层材料</label>
            <div class="layui-input-inline">
                <select name="layerMaterial">
                    <option value="">请选择</option>
                    <option value="sr">Sr</option>
                    <option value="ci">Ci</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">表明处理说明</label>
            <div class="layui-input-inline">
                <input name="surfaceTreatmentExplain" placeholder="请输入表明处理说明" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">选择单位</label>
            <div class="layui-input-inline">
                <select lay-filter="units" name="units" id="units" class="selectDisabled">
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">附件</label>
            <div class="layui-input-block">
                <!--<div id="btnUpload15" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件
                </div>
                <div id="btnUpload15_path" style="margin-left: 150px;line-height: 40px;"></div>
                <input id="btnUpload15_file" name="enclosure" type="hidden"/>-->
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">单价</label>
            <div class="layui-input-inline">
                <input name="unitPrice" placeholder="请输入单价" type="text" class="layui-input" lay-verify="required"
                       required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">交货时间</label>
            <div class="layui-input-inline">
                <input name="deliveryTime" id="deliveryTime" placeholder="yyyy-MM-dd" type="text" class="layui-input"
                       lay-verify="required" required/>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label width105">备注</label>
            <div class="layui-input-inline">
                <textarea name="remark" maxlength="200" class="layui-textarea"></textarea>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">审批人</label>
            <div class="layui-input-inline">
                <select lay-filter="approver" name="approver" id="approver" class="selectDisabled"></select>
            </div>
        </div>
        <div class="layui-form-item text-right">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="customerProductCatalogFormSubmit" lay-submit>保存</button>
        </div>
    </form>
</script>

<!--选择联系人下拉框-->
<script type="text/html" id="contactNameTemplate">
    <form lay-filter="addCustomerProductForm" class="layui-form model-form" style="padding: 0;">
        <select name="contactId" id="contactId" lay-filter="contactId" lay-verify="required"></select>
    </form>
</script>
<!--物料添加-->
<script type="text/html" id="addCustomerProduct">
    <div class="layui-card">
        <div class="layui-card-body">
            <form lay-filter="addCustomerProductForm" id="addCustomerProductForm" class="layui-form model-form"
                  style="padding: 0px 10px 0px 0px">
                <div class="layui-row table-bor storageWorkIsSelect" style="margin-top: 0px">
                    <div>客户与订单信息：</div>
                    <div class="layui-form-item">
                        <label class="layui-form-label ">平台产品编码</label>
                        <div class="layui-input-inline">
                            <input name="platformProductCode" id="platformProductCode" class="layui-input"
                                   type="text" placeholder="请输入平台产品系列" disabled/>
                        </div>
                    </div>

                    <!--                    <table class="layui-table" id="customerTable2" lay-filter="customerTable2"></table>-->
                </div>

                <div class="layui-row table-bor storageWorkIsSelect" style="margin-top: 20px">
                    <span>客户物料信息：</span>

                    <!--<table class="layui-table" id="customerProductTable" lay-filter="customerProductTable"></table>-->
                    <!--                    <table class="layui-table" id="customeProTable">-->
                    <!--                        <thead>-->
                    <!--                        <tr>-->
                    <!--                            <th style="text-align: center;">客户物料名称</th>-->
                    <!--                            <th style="text-align: center;">客户物料编号</th>-->
                    <!--                            <th style="text-align: center;">客户规格码</th>-->
                    <!--                            <th style="text-align: center;">上传附件</th>-->
                    <!--                            <th style="text-align: center;">是否需要包装</th>-->
                    <!--                            <th style="text-align: center;">包装说明</th>-->
                    <!--                        </tr>-->
                    <!--                        </thead>-->
                    <!--                        <tbody>-->
                    <!--                        <tr>-->
                    <!--                            <td>&lt;!&ndash;客户物料名称&ndash;&gt;-->
                    <!--                                <input type="text" name="extProductName" placeholder="请输入客户物料名称"-->
                    <!--                                       autocomplete="off"-->
                    <!--                                       class="layui-input" style="text-align: center;">-->
                    <!--                            </td>-->
                    <!--                            <td>&lt;!&ndash;客户物料编号&ndash;&gt;-->
                    <!--                                <input type="text" name="extProductCode" placeholder="请输入客户物料编号"-->
                    <!--                                       autocomplete="off"-->
                    <!--                                       class="layui-input" style="text-align: center;">-->
                    <!--                            </td>-->
                    <!--                            <td>&lt;!&ndash;客户规格码&ndash;&gt;-->
                    <!--                                <input type="text" name="extSpecCode" placeholder="请输入客户规格码" autocomplete="off"-->
                    <!--                                       class="layui-input" style="text-align: center;">-->
                    <!--                            </td>-->
                    <!--                            <td style="width: 300px;">&lt;!&ndash;上传附件&ndash;&gt;-->
                    <!--                                <div id="btnUpload15" class="layui-btn" style="float: left;"><i class="layui-icon">&#xe681;</i>上传文件-->
                    <!--                                </div>-->
                    <!--                                <div id="btnUpload15_path" style="margin-left: 150px;line-height: 30px;"></div>-->
                    <!--                                <input id="btnUpload15_file" name="enclosure" type="hidden"/>-->
                    <!--                            </td>-->
                    <!--                            <td>&lt;!&ndash;是否需要包装&ndash;&gt;-->
                    <!--                                <select name="packing" id="packing" lay-filter="packing">-->
                    <!--                                    <option value="">请选择是否需要包装</option>-->
                    <!--                                    <option value="0">需要</option>-->
                    <!--                                    <option value="1">不需要</option>-->
                    <!--                                </select>-->
                    <!--                            </td>-->
                    <!--                            <td>&lt;!&ndash;包装说明&ndash;&gt;-->
                    <!--                                <input type="text" name="packingRequire" placeholder="请输入包装说明" autocomplete="off"-->
                    <!--                                       class="layui-input" style="text-align: center;">-->
                    <!--                            </td>-->
                    <!--                        </tr>-->
                    <!--                        </tbody>-->
                    <!--                    </table>-->
                </div>


                <div class="layui-form-item text-right">
                    <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
                    <button class="layui-btn" type="button" lay-filter="addCustomerProductSubmit"
                            id="addCustomerProductSubmit" lay-submit>提交
                    </button>
                </div>
            </form>
        </div>
    </div>
</script>


<!-- js部分 -->
<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'laydate'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laydate = layui.laydate;
        var laytpl = layui.laytpl;

        laytpl(searchContent.innerHTML).render({}, function (html) {
            $('#searchDIV').html(html);
            form.render('select')
        });
        // 渲染表格
        var insTb = table.render({
            elem: '#customerProductCatalogTable',
            url: config.base + 'enterprise/sell/admin/customerProductCatalog/list',
            toolbar: true,
            defaultToolbar: ["filter"],
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type: 'numbers'}
                , {field: 'cusSkuCode', align: 'center', title: '客户物料编号', width: 120}
                , {field: 'cusProductName', align: 'center', title: '客户物料名称', width: 120}
                , {field: 'cusProductSpec', align: 'center', title: '客户规格码'}
                , {
                    field: 'skuCode', align: 'center', title: '内部物料料号', width: 120, templet: (d) => {
                        return d.skuCode ? d.skuCode : '未关联sku'
                    }
                }
                , {field: 'proTypeName', align: 'center', title: '内部物料类型'}
                , {field: 'customerName', align: 'center', title: '所属客户'}
                , {field: 'proUnitName', align: 'center', title: '主计量单位'}
                // , {field: '', align: 'center', title: '单价'}
                , {
                    field: 'enclosure', align: 'center', title: '附件', templet: (d) => {
                        if (d.enclosure) {
                            return `<a href="${d.enclosure}" style="color: blue" >下载附件</a>`;
                        } else {
                            return `-`;
                        }
                    }
                }
                , {field: 'remark', align: 'center', title: '备注'}

                // , {
                //     field: 'packing', align: 'center', title: '是否需要包装', templet: function (d) {
                //         if (d.packing) {
                //             return '需要'
                //         }
                //         return '不需要'
                //     }
                // }
                // , {field: 'packName', align: 'center', title: '包装方式'}
                // , {field: 'remark', align: 'center', title: '备注'}
                , {align: 'center', toolbar: '#customerProductCatalogTableBar', title: '操作', width: 200}
            ]],
            done: function (res, curr, count) {

            }
        });
        // table.render({
        //     elem: '#customerTable',
        //     url: config.base + 'enterprise/sell/admin/customersInfo/list',
        //     page: false,
        //     cellMinWidth: 100,
        //     cols: [[
        //         {type: 'numbers'}
        //         , {field: 'customerName', align: 'center', title: '客户名称'}
        //         , {field: 'id', align: 'center', title: '客户编码'}
        //         , {field: 'contactName', align: 'center', title: '客户联系人'}
        //         , {field: 'agentName', align: 'center', title: '所属渠道'}
        //         , {field: 'agtLevelName', align: 'center', title: '客户级别'}
        //         , {field: 'createTime', align: 'center', title: '录入时间', width: 180}
        //         , {field: 'creatorName', align: 'center', title: '客服代表'}
        //     ]],
        //     done: function (res, curr, count) {
        //
        //     }
        // });

        // 工具条点击事件
        table.on('tool(customerProductCatalogTable)', function (obj) {
            var data = obj.data;
            console.log('obj', obj)
            if (obj.event === 'edit') { //修改
                admin.req('enterprise/sell/admin/customerProductCatalog/detail/' + obj.data.id, {}, function (res) {
                    admin.formOpen({
                        area: ['90%', '85%'],
                        offset: ['5%', '5%'],
                        title: "修改",
                        path: 'components/sell/customerProductCatalogUserForm.html',
                        success: function () {
                            parentData.data = res.data
                            parentData.eventName = 'edit'
                        }
                    })
                })
            } else if (obj.event === 'del') { // 删除
                doDelete(obj);
            } else if (obj.event === 'detail') {
                admin.req('enterprise/sell/admin/customerProductCatalog/detail/' + obj.data.id, {}, function (res) {
                    admin.formOpen({
                        area: ['90%', '85%'],
                        offset: ['5%', '5%'],
                        title: "查看物料详情",
                        path: 'components/sell/customerProductCatalogUserForm.html',
                        success: function () {
                            parentData.data = res.data
                            parentData.eventName = 'detail'

                        }
                    })
                })

            }
        });

        //监听排序
        table.on('sort(customerProductCatalogTable)', function (obj) {
            table.reload('customerProductCatalogTable', {
                initSort: obj
                , where: {
                    sort: obj.field
                    , order: obj.type
                }
            });
        });

        // 搜索
        form.on('submit(formSubSearchLog)', function (data) {
            insTb.reload({where: data.field, page: {curr: 1}}, 'data');
        });



        //导入excel
        $('#uploaderInput').on("change", function (e) {
            layer.load(2);
            var formData = new FormData();
            var files = e.target.files;
            let that = $(this);
            formData.append("file", files[0]);
            formData.append("name", files[0].name);//这个地方可以传递多个参数
            $.ajax({
                url: config.base + 'enterprise/sell/admin/customerProductCatalog/importExcel',
                data: formData,
                headers: {Authorization: 'Bearer ' + config.getToken()},
                type: "POST",
                processData: false,
                contentType: false,
                success: function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        // table.reload('humanResourcesTable');
                        layer.closeAll('page');
                        setTimeout(_ => {
                            location.reload()
                        }, 1000);
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                    that.val('');
                }
            });
        })

        // 重置搜索
        form.on('submit(resets)', function (data) {
            $(".lay-header").find('select').val("");
            $(".lay-header").find('input').val("");
            let field = data.field;
            for (let key in field) {
                field[key] = ''
            }
            insTb.reload({where: field, page: {curr: 1}}, 'data');
        });

        // 添加按钮点击事件
        $('#customerProductCatalogBtnAdd').click(function () {
            showEditModel();
        });
        // 添加物料
        $('#addSelfCollectedGoodsBtn').click(() => {
            showAddCustomerProduct();
        });

        //下载模版
        $('#gigili').click(() => {
            window.location.href = config.base + 'enterprise/sell/admin/customerProductCatalog/template';
        });

        // 显示编辑弹窗
        function showEditModel(data) {
            admin.open({
                type: 1,
                area: '920px',
                offset: '65px',
                title: data ? '修改客户物料目录' : '添加客户物料目录',
                content: $('#customerProductCatalogForm').html(),
                success: function () {
                    if (data) {
                        var option = $("form select[name='packing']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.packing == item.text) {
                                data.packing = item.value;
                            }
                        });
                    }

                    if (data) {
                        var option = $("form select[name='surfaceTreatment']").find("option");
                        layui.each(option, function (index, item) {
                            if (data.surfaceTreatment == item.text) {
                                data.surfaceTreatment = item.value;
                            }
                        });
                    }

                    //时间选择器
                    laydate.render({
                        elem: '#deliveryTime'
                        , type: 'date'
                    });

                    admin.req('user/admin/companyInfo/list', {}, function (res) {
                        loadSelectHtml(res.data, "请选择客户", "customerId", "name");
                        if (data) {
                            $("#customerId").val(data.customerId);
                            form.render('select');
                        }
                    }, 'get')

                    //加载物料类型
                    admin.req('enterprise/product/admin/productType/getProductTypeByType', {type: 0}, function (res) {
                        loadSelectHtml(res.data, "请选择物料类型", "productType", "name");

                        if (data) {
                            $("#productType").val(data.productType);
                            form.render('select');

                            admin.req('enterprise/product/admin/productUnit/getProductUnitByType', {
                                type: 0,
                                productTypeId: data.productType
                            }, function (res) {
                                loadSelectHtml(res.data, "请选择单位", "units", "name");
                                if (data) {
                                    $("#units").val(data.units);
                                    form.render('select');
                                }
                            }, 'get');
                        }
                    }, 'get');

                    //加载品牌
                    admin.req('enterprise/product/admin/productBrand/getAllProductBrandByType', {type: 0}, function (res) {
                        loadSelectHtml(res.data, "请选择品牌", "productBrand", "name");
                        if (data) {
                            $("#productBrand").val(data.productBrand);
                            form.render('select');
                        }
                    }, 'get');

                    //加载物料单位
                    form.on('select(productType)', function (data) {
                        admin.req('enterprise/product/admin/productUnit/getProductUnitByType', {
                            type: 0,
                            productTypeId: data.value
                        }, function (res) {

                            loadSelectHtml(res.data, "请选择单位", "units", "name");
                            if (data) {
                                $("#units").val(data.units);
                                form.render('select');
                            }
                        }, 'get');
                    });

                    //加载审批人
                    admin.req('user/admin/user/list', {}, function (res) {
                        loadSelectHtml(res.data, "请选择审批人", "approver", "username");
                        if (data) {
                            $("#approver").val(data.approver);
                            form.render('select');
                        }
                    }, 'get')

                    //上传附件
                    upload.render({
                        elem: '#btnUpload15'
                        , url: config.upload_url + 'upload?path=' + img_path
                        , data: {}
                        , accept: 'file'
                        , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                        , headers: {authorization: 'Bearer ' + config.getToken()}
                        , done: function (res) {
                            if (res.code == 200) {

                                layer.msg(res.msg || "上传成功", {icon: 1});
                                var imagUrl = res.data.url;
                                $('#btnUpload15_path').html('<img src="' + imagUrl + '" style="height: 35px;" />');
                                $('#btnUpload15_file').val(imagUrl);
                            } else if (res.code == 502) {
                                return location.replace('admin/login.html');
                            } else {
                                layer.msg(res.msg || "上传失败", {icon: 2});
                            }
                        }
                    });
                    if (data && data.enclosure) {
                        $('#btnUpload15_path').html('<img src="' + data.enclosure + '" style="height: 35px;" />');
                    }

                    form.val('customerProductCatalogForm', data);
                    // 表单提交事件
                    form.on('submit(customerProductCatalogFormSubmit)', function (d) {
                        layer.load(2);
                        admin.req(data ? 'enterprise/sell/admin/customerProductCatalog/update' : 'enterprise/sell/admin/customerProductCatalog/add', d.field, function (res) {
                            layer.closeAll('loading');
                            if (res.code == 200) {
                                layer.msg(res.msg, {icon: 1});
                                table.reload('customerProductCatalogTable');
                                layer.closeAll('page');
                            } else {
                                layer.msg(res.msg, {icon: 2});
                            }
                        }, data ? 'PUT' : 'POST');
                        return false;
                    });
                }
            });
        }

        // 删除
        function doDelete(obj) {
            layer.confirm('确定要删除吗？', {
                offset: '65px',
                skin: 'layui-layer-admin'
            }, function (i) {
                layer.close(i);
                layer.load(2);
                admin.req('enterprise/sell/admin/customerProductCatalog/' + obj.data.id, {}, function (res) {
                    layer.closeAll('loading');
                    if (res.code == 200) {
                        layer.msg(res.msg, {icon: 1});
                        obj.del();
                    } else {
                        layer.msg(res.msg, {icon: 2});
                    }
                }, 'DELETE');
            });
        }

        // 添加物料
        function showAddCustomerProduct(data) {
            admin.formOpen({
                area: ['90%', '85%'],
                title: "添加物料",
                path: 'components/sell/customerProductCatalogUserForm.html'
            })
            // admin.open({
            //     type: 1,
            //     area: ["80%"],
            //     offset: ['10%', '10%'],
            //     title: data ? '详情' : '添加物料',
            //     content: $('#addCustomerProduct').html(),
            //     success: function () {
            //         let addCustomerProductListData = [], specificationCode = [];
            //         let getProductInfoBySkuCodeData = '';
            //
            //         //请求物料类型
            //         admin.req('enterprise/product/admin/productType/getProductTypeByType', {type: 0}, function (res) {
            //             loadSelectHtml(res.data, "请选择物料类型", "productTypeId", "name");
            //
            //             if (data) {//回显值
            //                 $("#productTypeId").val(data.productTypeId);
            //                 form.render('select');
            //
            //                 //加载基础单位
            //                 admin.req('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
            //                     type: 0,
            //                     productTypeId: data.productTypeId
            //                 }, function (res) {
            //                     $("#unitId").val(res.data.id);
            //                     $("#unitName").val(res.data.name);
            //                 }, 'get');
            //
            //                 //包装单位
            //                 admin.req('enterprise/product/admin/productUnit/getProductUnitByType', {
            //                     type: 0,
            //                     productTypeId: data.productTypeId
            //                 }, function (res) {
            //                     loadSelectHtml(res.data, "请选择包装单位", "packUnitId", "name");
            //                     if (data) {
            //                         $("#packUnitId").val(data.packUnitId);
            //                         form.render('select');
            //                     }
            //                 }, 'get');
            //
            //                 //包装方案
            //                 admin.req('enterprise/product/admin/productPack/getByProductTypeId', {
            //                     type: 0,
            //                     productTypeId: data.productTypeId
            //                 }, function (res) {
            //                     loadSelectHtml(res.data, "请选择包装方案", "productPack", "name");
            //                     if (data) {
            //                         $("#productPack").val(data.productPack);
            //                         form.render('select');
            //                     }
            //                 }, 'get');
            //
            //                 //客户联系人
            //                 admin.req('enterprise/sell/admin/contactInfo/list', {
            //                     selCustomerId: data.customerId,
            //                     id: data.contactId
            //                 }, function (res) {
            //                     loadSelectHtml(res.data, "请选择", "contactId", "name");
            //                     $("#contactId").val(data.contactId);
            //                     form.render('select');
            //                 }, 'GET');
            //
            //                 $("input[name='remark']").val(data.remark);
            //                 $("input[name='skuCode']").val(data.skuCode);
            //                 $("input[name='skuName']").val(data.skuName);
            //                 $("input[name='weight']").val(data.weight);
            //
            //                 //客户物料信息
            //                 $("input[name='extProductName']").val(data.extProductName);
            //                 $("input[name='extProductCode']").val(data.extProductCode);
            //                 $("input[name='extSpecCode']").val(data.extSpecCode);
            //
            //
            //                 if (data.packing) {
            //                     let select = 'dd[lay-value=0]';
            //                     $('#packing').siblings("div.layui-form-select").find('dl').find(select).click();
            //                 } else {
            //                     let select = 'dd[lay-value=1]';
            //                     $('#packing').siblings("div.layui-form-select").find('dl').find(select).click();
            //                 }
            //
            //                 $("input[name='packingRequire']").val(data.packingRequire);
            //
            //                 //**设置禁止选择：**//
            //                 $("#packing").attr("disabled", "disabled");
            //                 $("#productTypeId").attr("disabled", "disabled");
            //                 $("#packUnitId").attr("disabled", "disabled");
            //                 $("#productPack").attr("disabled", "disabled");
            //                 $("#productRange").attr("disabled", "disabled");
            //
            //
            //             }
            //         }, 'get');
            //
            //         form.on('select(productTypeId)', function (data) {
            //             //加载基础单位
            //             admin.req('enterprise/product/admin/productUnit/getIsBaseUnitProductUnitByType', {
            //                 type: 0,
            //                 productTypeId: data.value
            //             }, function (res) {
            //                 $("#unitId").val(res.data.id);
            //                 $("#unitName").val(res.data.name);
            //             }, 'get');
            //
            //             //包装单位
            //             admin.req('enterprise/product/admin/productUnit/getProductUnitByType', {
            //                 type: 0,
            //                 productTypeId: data.value
            //             }, function (res) {
            //                 console.log(res.data);
            //                 loadSelectHtml(res.data, "请选择包装单位", "packUnitId", "name");
            //                 if (data) {
            //                     $("#packUnitId").val(data.packUnitId);
            //                     form.render('select');
            //                 }
            //             }, 'get');
            //
            //             //包装方案
            //             admin.req('enterprise/product/admin/productPack/getByProductTypeId', {
            //                 type: 0,
            //                 productTypeId: data.value
            //             }, function (res) {
            //                 loadSelectHtml(res.data, "请选择包装方案", "productPack", "name");
            //                 if (data) {
            //                     $("#productPack").val(data.productPack);
            //                     form.render('select');
            //                 }
            //             }, 'get');
            //
            //
            //             //规格数据
            //             admin.reqSync('enterprise/product/admin/productSpec/getProductSpecByProductTypeId', {productTypeId: data.value}, res => {
            //                 if (res.code === 200) {
            //                     specificationCode = res.data;
            //                 }
            //             }, 'get');
            //
            //             addCustomerProductListData.push({
            //                 index: 1,
            //                 isShow: true,
            //                 specificationCode: specificationCode,
            //                 skuSpecValueNames: []
            //             })
            //             table.reload('specValue', {data: addCustomerProductListData});
            //             console.log("addCustomerProductListData:" + addCustomerProductListData);
            //
            //         });
            //
            //
            //         //物料系列
            //         admin.req('enterprise/product/admin/product/list', {}, function (res) {
            //             loadSelectHtml(res.data, "请选择物料系列", "productRange", "name");
            //             if (data) {
            //                 $("#productRange").val(data.productRange);
            //                 form.render('select');
            //                 admin.req('enterprise/product/admin/product/getProductById', {productId: data.productRange}, function (res) {
            //                     $("#rangeCode").val(res.data.productCode)
            //                 }, 'get');
            //             }
            //         });
            //         //物料系列编码
            //         form.on('select(productRange)', function (data) {
            //             admin.req('enterprise/product/admin/product/getProductById', {productId: data.value}, function (res) {
            //                 $("#rangeCode").val(res.data.productCode)
            //             }, 'get');
            //         });
            //
            //         // let addGoodsTbList = table.render({
            //         //     elem: '#specValue',
            //         //     page: false,
            //         //     cellMinWidth: 110,
            //         //     data: addCustomerProductListData,
            //         //     limit: Number.MAX_VALUE,
            //         //     height: 250,
            //         //     cols: [[
            //         //         {
            //         //             field: '', width: '550', templet: d => {
            //         //                 let selectHTML = '', skuSpecValueNamesValue = '', skuSpecValueNamesString = '';
            //         //                 d.skuSpecValueNames.forEach(item => skuSpecValueNamesString += item.name + '-');
            //         //                 selectHTML += `<span style="display:${d.isShow == true ? 'none' : ''}">${skuSpecValueNamesString.substring(0, skuSpecValueNamesString.length - 1)}</span>`;
            //         //
            //         //                 d.specificationCode.forEach((item, index) => {
            //         //                     let skuSpecValueNamesValueSelect = '';
            //         //                     selectHTML += `<div class="skuSpecValueNames" style="width: 130px;float: left;margin:5px 5px 0 0; display:${d.isShow == true ? '' : 'none'}">
            //         //                                    <select class="skuSpecValueNamesList"  name="${d.index + '-' + item.id}" id="${d.index + '-' + item.id}" style="margin-bottom: 5px" lay-search="">`;
            //         //                     selectHTML += '<option value="">' + item.name + '</option>';
            //         //                     if (d.skuSpecValueNames[index]) {
            //         //                         skuSpecValueNamesValue = d.skuSpecValueNames[index].value;
            //         //                     } else {
            //         //                         skuSpecValueNamesValue = '';
            //         //                     }
            //         //                     item.productSpecValueList.forEach(itemList => {
            //         //                         if (skuSpecValueNamesValue == itemList.id) {
            //         //                             skuSpecValueNamesValueSelect = 'selected=""'
            //         //                         } else {
            //         //                             skuSpecValueNamesValueSelect = ''
            //         //                         }
            //         //                         if (item.specCode == 'is') {
            //         //                             if (item.specLocation == 'last') {
            //         //                                 selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + itemList.value + item.specHead + '</option>'
            //         //                             } else {
            //         //                                 selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + item.specHead + itemList.value + '</option>'
            //         //                             }
            //         //
            //         //                         } else {
            //         //                             selectHTML += '<option ' + skuSpecValueNamesValueSelect + ' value="' + itemList.id + '" skuSpec="' + item.id + '" >' + itemList.value + '</option>'
            //         //                         }
            //         //                     });
            //         //
            //         //                     selectHTML += '</select></div>';
            //         //
            //         //                 });
            //         //                 return selectHTML;
            //         //             }
            //         //         }
            //         //     ]]
            //         // });
            //
            //
            //         //加载物料分类树级菜单
            //         var arr2tree;
            //         admin.req('enterprise/product/admin/productCategory/getProductCategoryByType', {type: 0}, function (res) {
            //             for (let i = 0; i < res.data.length; i++) {
            //                 res.data[i].children = [];
            //             }
            //             arr2tree = xmSelect.arr2tree(res.data, "parentId", "id", "children", -1);
            //         }, 'get', false);
            //
            //         var selectedData = function (treeData, targetId) {
            //
            //             for (var k = 0; k < treeData.length; k++) {
            //                 var nodeId = treeData[k].id;
            //                 if (targetId == nodeId) {
            //                     treeData[k].selected = true;
            //                     return;
            //                 } else {
            //                     if (treeData[k].children && treeData[k].children != '') {
            //                         selectedData(treeData[k].children, targetId);
            //                     }
            //                 }
            //             }
            //         }
            //
            //         if (data) {
            //             selectedData(arr2tree, data.productCategoryId);
            //         }
            //
            //         // var smlSelectInstans = xmSelect.render({
            //         //     el: '#productCategoryId',
            //         //     model: {label: {type: 'text'}},
            //         //     radio: true,
            //         //     clickClose: true,
            //         //     filterable: true,
            //         //     tree: {
            //         //         show: true,
            //         //         strict: false,
            //         //         expandedKeys: [-1],
            //         //     },
            //         //     tips: '请选择物料分类',
            //         //     prop: {
            //         //         name: 'name',
            //         //         value: 'id',
            //         //         children: 'children'
            //         //     },
            //         //     data() {
            //         //         //填充数据
            //         //         return arr2tree;
            //         //     },
            //         //     on(data) {
            //         //         let parentId = data.arr.length > 0 ? data.change[0].id : -1;
            //         //         $("input[name='productCategoryId']").val(parentId);
            //         //     }
            //         // });
            //
            //         //上传附件
            //         uploadImg("btnUpload15", "btnUpload15_path", "btnUpload15_file");
            //
            //         if (data && data.enclosure) {
            //             $('#btnUpload15_path').html('<img src="' + data.enclosure + '" style="height: 35px;" />');
            //             layer.photos({
            //                 photos: '.uploadImgStyle'
            //                 , anim: 5
            //             });
            //         }
            //
            //         form.val('addCustomerProductFrom', data);
            //         // 表单提交事件
            //         form.on('submit(addCustomerProductSubmit)', function (d) {
            //             layer.load(2);
            //             let skuData = [], extProductData = [], listDataObj = {};
            //             let skuObj = {};
            //             let extProduct = {};
            //             let row = $("[lay-id=specValue] table tbody tr");
            //             let skuString = '', skuSpecValueString = '', skuSpecString = '';
            //             for (let i = 0; i < row.length; i++) {
            //                 for (let j = 0; j < row.eq(i).find(".skuSpecValueNames").find('select').length; j++) {
            //                     if (row.eq(i).find(".skuSpecValueNames").find('input').eq(j).val() == '') {
            //                         skuString = '';
            //                         skuSpecValueString = '';
            //                         skuSpecString = '';
            //                     } else {
            //                         skuString += row.eq(i).find(".skuSpecValueNames").find('input').eq(j).val() + '-';
            //                         skuSpecValueString += row.eq(i).find(".skuSpecValueNames").find('option:selected').eq(j).val() + '_';
            //                         skuSpecString += row.eq(i).find(".skuSpecValueNames").find('option:selected').eq(j).attr('skuspec') + '_';
            //                     }
            //                 }
            //             }
            //             let skuSpecValueNames = skuString.substring(0, skuString.length - 1);
            //             let skuSpecValue = skuSpecValueString.substring(0, skuSpecValueString.length - 1);
            //             let skuSpec = skuSpecString.substring(0, skuSpecString.length - 1);
            //             //alert("skuSpecValueNames:"+skuSpecValueNames+"   skuSpecValue"+skuSpecValue);
            //             //取值
            //             var contactId = $("#contactId").val();
            //             var extProductName = addCustomerProductForm.extProductName.value;
            //             var extProductCode = addCustomerProductForm.extProductCode.value;
            //             var extSpecCode = addCustomerProductForm.extSpecCode.value;
            //             var enclosure = addCustomerProductForm.enclosure.value;
            //             var packing = $("#packing").val();//获取是否包装当前选择项值
            //             if (packing == 1 || !packing) {
            //                 packing = false;
            //             } else {
            //                 packing = true;
            //             }
            //
            //             var packingRequire = addCustomerProductForm.packingRequire.value;
            //             var productTypeId = $("#productTypeId").val();
            //             var productCategoryId = addCustomerProductForm.productCategoryId.value;
            //             var productRange = $("#productRange").val();
            //             /* var rangeCode = addCustomerProductForm.rangeCode.value;
            //              var unitId = document.getElementById("unitId").value;*/
            //             var remark = addCustomerProductForm.remark.value;
            //             var skuCode = addCustomerProductForm.skuCode.value;
            //             var skuName = addCustomerProductForm.skuName.value;
            //             var packUnitId = $("#packUnitId").val();
            //             var productPack = $("#productPack").val();
            //             var weight = addCustomerProductForm.weight.value;
            //
            //             /*var options=$("# option:selected");//获取当前选择项.
            //             options.val();//获取当前选择项的值.*/
            //
            //             skuObj = {
            //                 skuCode: skuCode,
            //                 skuName: skuName,
            //                 oldSpecCode: extSpecCode,
            //                 unitId: packUnitId,
            //                 packId: productPack,
            //                 skuSpecValueNames: skuSpecValueNames,
            //                 skuSpecValue: skuSpecValue,
            //                 skuSpec: skuSpec,
            //                 productTypeId: productTypeId,
            //                 productCategoryId: productCategoryId,
            //                 productId: productRange,
            //                 remark: remark,
            //                 weightNumber: weight
            //             };
            //
            //             extProduct = {
            //                 name: extProductName,
            //                 code: extProductCode,
            //                 spec: extSpecCode,
            //                 hasPack: packing,
            //                 packInstructions: packingRequire
            //             }
            //
            //             skuData.push(skuObj);
            //             extProductData.push(extProduct);
            //             console.log("skuData: " + skuData);
            //             console.log("extProductData: " + extProductData);
            //
            //             listDataObj.productDetailForm = skuData;
            //             listDataObj.externalProductForm = extProductData;
            //             listDataObj.customerId = '';
            //             listDataObj.contactId = contactId;
            //             listDataObj.skuCode = skuCode;
            //             listDataObj.enclosure = enclosure;
            //             listDataObj.extProductCode = extProductCode;
            //             console.log("listDataObj: " + listDataObj);
            //
            //             admin.req('enterprise/sell/admin/customerProductCatalog/addProduct', JSON.stringify(listDataObj), function (res) {
            //                 layer.closeAll('loading');
            //                 if (res.code === 200) {
            //                     layer.closeAll();
            //                     layer.msg(res.msg, {icon: 1});
            //                     table.reload('customerProductCatalogTable');
            //                 } else {
            //                     layer.msg(res.msg, {icon: 2});
            //                 }
            //             }, 'POST', true, 'application/json; charset=utf-8');
            //         });
            //
            //     }
            // })
        }

        /**
         * 加载地址HTML
         * @param data 下拉菜单数据
         * @param tips select 默认提示
         * @param htmltarget html要插入的位置
         * @param name  下拉框需要显示值的属性
         */
        function loadSelectHtml(data, tips, htmltarget, name) {
            let html = ' <option value>' + tips + '</option>';
            if (!data || data == null) {
                return;
            }
            for (let i = 0; i < data.length; i++) {
                html += `<option value='${data[i].id}'>${data[i][name]}</option>`;
            }
            $("[name='" + htmltarget + "']").html(html);
            form.render('select');
        }

        // 上传图片
        function uploadImg(_elem, pathId, inputId) {
            upload.render({
                elem: '#' + _elem
                , url: config.upload_url + 'uploadFile'
                , data: {}
                , accept: 'file'
                , exts: 'jpg|png|RAR|zip|pdf|txt|doc|docx|xls|xlsx|ppt|pptx'
                , headers: {Authorization: 'Bearer ' + config.getToken()}
                , done: function (res) {
                    if (res.code == 200) {
                        layer.msg(res.msg || "上传成功", {icon: 1});
                        let imagUrl = res.data.url;
                        $('#' + pathId).html('<img src="' + imagUrl + '"/>');
                        $('#' + inputId).val(imagUrl);
                    } else if (res.code == 502) {
                        return location.replace('admin/login.html');
                    } else {
                        layer.msg(res.msg || "上传失败", {icon: 2});
                    }
                }
            });
        }


    });
</script>